import BaseComponent from "../../BaseComponent";
import {LIGHT_HEAD_TYPE, PackageFactory} from "../../../service/LightTpService";
import BluDeviceComService from "../../../service/BluDeviceComService";
import {Button, View} from "@tarojs/components";

export default class CmdSendView extends BaseComponent {

  sendData = (factory, args) => {

    const {deviceId} = this.props;

    let arr = [];
    if (!args)
      arr = factory();
    else
      arr = factory(...args);
    BluDeviceComService.sendData(deviceId, arr);
  }

  render() {

    const datas = [
      {
        value: '控制开机',
        send: () => {
          this.sendData(PackageFactory.open);
        }
      },
      {
        value: '控制关机',
        send: () => {
          this.sendData(PackageFactory.close);
        }
      },
      {
        value: '询问参数',
        send: () => {
          this.sendData(PackageFactory.ask);
        }
      },
      {
        value: '设置音量',
        send: () => {
          this.sendData(PackageFactory.setVol, [5]);
        }
      },
      {
        value: '设置时间',
        send: () => {
          this.sendData(PackageFactory.setTime);
        }
      },
      {
        value: '开机时间',
        send: () => {
          this.sendData(PackageFactory.setTimeOC, [[16, 10, 10], [17, 10, 10], 1, 1]);
        }
      },
      {
        value: '延时关机',
        send: () => {
          this.sendData(PackageFactory.setDelayClose, [60]);
        }
      },
      {
        value: '设置亮度',
        send: () => {
          this.sendData(PackageFactory.setBrightness, [100]);
        }
      },
      {
        value: '设置灯头',
        send: () => {
          this.sendData(PackageFactory.setHead, [LIGHT_HEAD_TYPE.dj, 3]);
        }
      },
      {
        value: '设置灯效',
        send: () => {
          this.sendData(PackageFactory.setBrightnessColor, [LIGHT_HEAD_TYPE.dj, 3, [0, 0, 0, 0, 0, 0]]);
        }
      },
      {
        value: '关闭背景',
        send: () => {
          this.sendData(PackageFactory.setBgm, [LIGHT_HEAD_TYPE.dj, 0]);
        }
      },
      {
        value: '关闭声控',
        send: () => {
          this.sendData(PackageFactory.setMic, [LIGHT_HEAD_TYPE.dj, 0]);
        }
      },
      {
        value: '设置声控强度',
        send: () => {
          this.sendData(PackageFactory.setMICLevel, [LIGHT_HEAD_TYPE.dj, 10]);
        }
      },
      {
        value: '询问版本号',
        send: () => {
          this.sendData(PackageFactory.askVersion);
        }
      },
    ];

    return <View className='at-row at-row--wrap'>
      {
        datas.map(data => {
          return <View className='at-col at-col-5'>
            <Button size="mini" onClick={data.send}>{data.value}</Button>
          </View>
        })
      }
    </View>
  }
}
